package cn.zd.erp.auth.dep.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import cn.zd.erp.auth.dep.service.ebi.Orgebi;
import cn.zd.erp.auth.dep.vo.Torganization1;
import cn.zd.erp.util.base.Json;
import cn.zd.erp.util.base.Organization;
import cn.zd.erp.util.base.Tree;
/**
 * 组织的Action类
 * @author hpx
 *
 */
//@Controller(value="organizationAction")
public class TorganizationAction {
	private Torganization1 torganization;
	@Autowired
	private Orgebi orgEbi;
	private List<Tree> tree;
	private List<Organization> treeGrid;
	private Json json  = new Json();;
	
	
	/**
	 * 跳转到主页面
	 * @return
	 */
	public String list() {
		return "list";
	}
	
	/**
	 * 添加页面跳转
	 * @return
	 */
	public String add() {
		return "add";
	}
	/**
	 *保存用户
	 * @return
	 */
	public String sava() {
		if(torganization.getId()!=null)
		{
			try {
				orgEbi.sava(torganization);
				json.setMsg("添加成功！");
				json.setSuccess(true);
			} catch (Exception e) {
				json.setMsg(e.getMessage());
			}
		}
		else{
			try {
				orgEbi.sava(torganization);
				json.setMsg("保存成功！");
				json.setSuccess(true);
			} catch (Exception e) {
				json.setMsg(e.getMessage());
			}
		}
	
		
		return "myjson";
	}

	
	/**
	 * 返回treeGrid
	 * @return
	 */
	public String treeGrid() {
		treeGrid = orgEbi.treeGrid();
		return "treeGridjson";
	}

	/**
	 * 返回下拉树
	 * @return
	 */
	public String tree() {
		tree = orgEbi.getAllOrg();
		return "treejson";
	}
	/**
	 * 删除用户并返回成功
	 * @return
	 */
	public String delete()
	{
		json = new Json();
		try {
			orgEbi.delete(torganization);
			json.setMsg("删除成功！");
			json.setSuccess(true);
		} catch (Exception e) {
			json.setMsg(e.getMessage());
		}
		return "myjson";
	}
	
	/**
	 * 跳转到编辑页面
	 * @return
	 */
	public String edit()
	{
		torganization = orgEbi.getOrgById(torganization.getId());
		return "edit";
	}
	public void setTorganization(Torganization1 torganization) {
		this.torganization = torganization;
	}

	public Torganization1 getTorganization() {
		return torganization;
	}
	public Json getJson() {
		return json;
	}
	public List<Organization> getTreeGrid() {
		return treeGrid;
	}
	public List<Tree> getTree() {
		return tree;
	}

}
